#include "individualreport.h"
#include "ui_individualreport.h"
#include "Beans/databean.h"
#include "QSettings"
IndividualReport::IndividualReport(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::IndividualReport)
{
    ui->setupUi(this);
    //设置控件属性
    InitialCotrols();

}

IndividualReport::~IndividualReport()
{
    delete ui;
}

/**
 * @brief IndividualReport::InitialCotrols
 * 功能：初始化控件
 */
void IndividualReport::InitialCotrols()
{
    ui->widget_KangYa->setRange(0, 100);
    ui->widget_KangYa->setFixedHeight(100);
    ui->widget_KangYa->setFixedWidth(600);
    ui->widget_KangYa->setStep(5, 2);
    ui->widget_KangYa->setSpace(8);
    ui->widget_KangYa->setSliderColor(QColor(89,189,255),QColor(255,255,255));

    ui->widget_KangYa->setPrecision(0);
    ui->widget_MentalPre->setRange(0, 100);
    ui->widget_MentalPre->setFixedHeight(100);
    ui->widget_MentalPre->setFixedWidth(600);
    ui->widget_MentalPre->setStep(5, 2);
    ui->widget_MentalPre->setSpace(8);
    ui->widget_MentalPre->setBgColor(QColor(47, 200, 0),QColor(255, 255, 120),QColor(200, 50, 20));
    ui->widget_MentalPre->setSliderColor(QColor(89,189,255),QColor(255,255,255));
    ui->widget_MentalPre->setPrecision(0);
    ui->widget_MentalPre->setValue(0);

    ui->widget_MentalFatigure->setRange(0, 100);
    ui->widget_MentalFatigure->setFixedHeight(100);
    ui->widget_MentalFatigure->setFixedWidth(600);
    ui->widget_MentalFatigure->setStep(5, 2);
    ui->widget_MentalFatigure->setSpace(8);
    ui->widget_MentalFatigure->setBgColor(QColor(47, 200, 0),QColor(255, 255, 120),QColor(200, 50, 20));
    ui->widget_MentalFatigure->setSliderColor(QColor(89,189,255),QColor(255,255,255));
    ui->widget_MentalFatigure->setPrecision(0);
    ui->widget_MentalFatigure->setValue(0);

    ui->widget_Emotion->setRange(0, 100);
    ui->widget_Emotion->setFixedHeight(100);
    ui->widget_Emotion->setFixedWidth(600);
    ui->widget_Emotion->setStep(5, 2);
    ui->widget_Emotion->setSpace(8);
    ui->widget_Emotion->setBgColor(QColor(200, 50, 20),QColor(47, 200, 0),QColor(200, 50, 20));
    ui->widget_Emotion->setSliderColor(QColor(89,189,255),QColor(255,255,255));
    ui->widget_Emotion->setPrecision(0);
    ui->widget_Emotion->setValue(0);


    ui->widget_activity->setRange(0, 100);
    ui->widget_activity->setFixedHeight(100);
    ui->widget_activity->setFixedWidth(600);
    ui->widget_activity->setStep(5, 2);
    ui->widget_activity->setSpace(8);
    ui->widget_activity->setSliderColor(QColor(89,189,255),QColor(255,255,255));

    ui->widget_ballance->setRange(0, 100);
    ui->widget_ballance->setFixedHeight(100);
    ui->widget_ballance->setFixedWidth(600);
    ui->widget_ballance->setStep(5, 2);
    ui->widget_ballance->setSpace(8);
    ui->widget_ballance->setSliderColor(QColor(89,189,255),QColor(255,255,255));



}
/**
 * @brief IndividualReport::setV
 * 功能：填写指标值
 * @param db
 */
void IndividualReport::setV(DataBean db)
{
    //设置单位名称
    QSettings settingsread("Option.ini",QSettings::IniFormat);
    QString DWName = settingsread.value("DevOption/Name").toString();
    ui->label_hospital->setText(DWName);
    // 用户基本信息
    ui->label_IDV->setText(db.UserID);
    ui->label_NameV->setText(db.UserName);
    ui->label_MeasureTimeV->setText(db.MeasureTime);
    ui->label_ThemeV->setText(db.Theme);
    ui->label_trainContentV->setText(db.TrainContent);
    ui->label_UseTimeV->setText(db.UseTime);
    // 绘制rr间期图
    createLineChart_RR(db.RR);
    // 绘制精神压力和自主神经功能状态
    ui->widget_ballance->setValue((int)db.hrvIndex.ai.Balance);
    ui->widget_activity->setValue((int)db.hrvIndex.ai.Activity);
    ui->widget_Emotion->setValue((int)db.hrvIndex.pi.ems);
    ui->widget_MentalFatigure->setValue((int)db.hrvIndex.pi.psi);
    ui->widget_MentalPre->setValue((int)db.hrvIndex.pi.mpi);
    ui->widget_KangYa->setValue((int)db.hrvIndex.pi.rpai);
    if(db.hrvIndex.ai.Balance>70)
        ui->label_Ballance->setText("很好");
    else if(db.hrvIndex.ai.Balance<30)
        ui->label_Ballance->setText("较差");
    else
        ui->label_Ballance->setText("适中");

    if(db.hrvIndex.ai.Activity>70)
        ui->label_Activity->setText("很好");
    else if(db.hrvIndex.ai.Activity<30)
        ui->label_Activity->setText("较差");
    else
        ui->label_Activity->setText("适中");

    if(db.hrvIndex.pi.ems>70)
        ui->label_Emotion->setText("焦虑");
    else if(db.hrvIndex.pi.ems<30)
        ui->label_Emotion->setText("消极");
    else
        ui->label_Emotion->setText("适中");

    if(db.hrvIndex.pi.psi>70)
        ui->label_Fatigure->setText("较大");
    else if(db.hrvIndex.pi.psi<30)
        ui->label_Fatigure->setText("较小");
    else
        ui->label_Fatigure->setText("适中");

    if(db.hrvIndex.pi.mpi>70)
        ui->label_Mp->setText("较大");
    else if(db.hrvIndex.pi.mpi<30)
        ui->label_Mp->setText("较小");
    else
        ui->label_Mp->setText("适中");

    if(db.hrvIndex.pi.rpai>70)
        ui->label_kangya->setText("较强");
    else if(db.hrvIndex.pi.rpai<30)
        ui->label_kangya->setText("较弱");
    else
        ui->label_kangya->setText("适中");
    // 生理指标
    ui->label_Score->setText(db.PysScore);
    ui->label_HR->setText(db.HR);
    ui->label_OX->setText(db.Ox);
    ui->label_SDP->setText(db.SDP);
    ui->textEdit->setText(db.Res_HRV+db.Res_MentalPressure);


}
/**
 * @brief IndividualReport::createLineChart_RR
 * 功能：创建rr间期图
 * @param RR
 * @return
 */
QChart *IndividualReport::createLineChart_RR(QList<int>RR)
{
    QChart *chart = new QChart();
    QLineSeries *series_RR = new QLineSeries;

    series_RR->setPen(QPen(QColor(0,0,0),5));
    chart->addSeries(series_RR);
    chart->createDefaultAxes();
    chart->setBackgroundVisible(true);
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));
    chart->axisY()->setRange(400, 1500);
    chart->axisX()->setRange(0, RR.size());

    for(int i=0;i<RR.size();i++)
    {
        series_RR->append(QPoint(i,RR.at(i)));
    }
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleText("ms");
    chart->axisY()->setTitleBrush(QBrush(QColor(0, 0, 0),Qt::SolidPattern));
    chart->axisY()->setLabelsColor(QColor(0, 0, 0));
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisX()->setLineVisible(false);
    chart->legend()->hide(); /* hide legend */
    chart->axisX()->setVisible(false);
    chart->axisY()->setVisible(true);
    ui->widget_hr->setChart(chart);
    ui->widget_hr->setRenderHint(QPainter::Antialiasing, true);
    return chart;
}
